<!--
 * @Author: ChunLai
 * @Date: 2023-08-03 11:44:01
 * @LastEditTime: 2025-09-04 18:32:52
 * @Description: 现金价值表---弹窗按钮
 * @FilePath: \02.bldinsure\src\components\cash\CashTableBtn.vue
-->
<template>
  <div>
    <div class="cash_btn" @click="getCashValue()">查看《现金价值表》</div>
    <van-popup v-model="show" :style="{ height: '100%' }" sticky>
      <CashValueTable
        :cashValues="cashValues"
        @closePop="show = false"
      ></CashValueTable>
    </van-popup>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import CashValueTable from "./CashValueTable";
export default {
  name: "CashTableBtn",
  data() {
    return {
      show: false,
      cashValues: [],
    };
  },
  components: { CashValueTable },
  computed: {
    ...mapGetters({
      showedRisks: "risks/showedRisks",
    }),
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    getCashValue() {
      this.$store
        .dispatch("apis/comAdminApiRequest", {
          apiParams: this.apiComParams,
          apiName: "queryCash",
          toast: true,
        })
        .then((data) => {
          // mainRiskCash 主险现金价值
          // lqCash 两全险现金价值
          // hmCash 豁免现金价值
          const risks = this.showedRisks;
          let arr = [];
          const obj1 = {
            proName: risks[0].productName,
            tableList: data.mainRiskCash,
          };
          arr.push(obj1);
          if (data.lqCash && data.lqCash.length > 0) {
            const findObj1 = risks.find((ele) =>
              ["412001"].includes(ele.varietyCode)
            );
            const obj2 = {
              proName: findObj1.productName,
              tableList: data.lqCash,
            };
            arr.push(obj2);
          }
          if (data.hmCash && data.hmCash.length > 0) {
            const findObj2 = risks.find((ele) =>
              ["415008"].includes(ele.varietyCode)
            );
            const obj3 = {
              proName: findObj2.productName,
              tableList: data.hmCash,
            };
            arr.push(obj3);
          }
          this.cashValues = arr;
          this.$nextTick(() => {
            this.show = true;
          });
        });
    },
  },
};
</script>

<style lang="less" scoped>
.cash_btn {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
  color: #4295e2;
}
</style>
